package com.yang.singleton;

/**
 * 饿汉式， 与Singleton1的区别就是实例化放在了静态代码块中
 * */
public class Singleton2 {


    //构造方法私有化
    private Singleton2(){}

    //class文件加载时进行类的实例化
    private static Singleton2 INSTANCE ;
    static {
        INSTANCE = new Singleton2();
    }

    public static Singleton2 getInstance() {
        return INSTANCE;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 50; i++) {
            new Thread(() -> {
                System.out.println(Singleton2.getInstance().hashCode());
            }).start();
        }
    }


}
